Welcome to this tutorial on running simulations with the UrbanScape Agent-based Model. By the end of this tutorial, you will be able to play with the different conditions that are encoded within the UrbanScape module and run in silico experiments to test and visualize the results of your hypotheses!
Before we dive into UrbanScape, it'll be useful to know about functions. They are much like the functions in math. Some function f takes an input x and gives an output y. In programming, a function takes one or more arguments, and returns an output.
But first, let me give you some problems to solve :)
In [ ]:
# assign 5 + 3 to the variable x
In [ ]:
# assign 1000 + 2 to the variable y
In [ ]:
# assign 1.041 + (-2.512) to the variable z
As a toy example, let's define a function that can perform addition so you don't have to type in the numbers and assign a variable to it each time. This is how you define a function in python:
def some_task(argument1, ...):
result = do_something
return result
In [2]:
# define your own addition function below
This seems pretty trivial right now, but to drive home the point of how awesome functions are, what if you wanted to perform this task over and over again? You can now use your addition function, or 'call' your addition function whenever you want.
In [ ]:
# apply the addition function to adding elements in two lists by index
In [2]:
# Type in and run importing script here
import UrbanScape.urbanscape as us
In [3]:
# set a variable size to 3
size = 3
# set a rent variable to 100
rent = 100
# create your first UrbanScape!
my_first_urbanscape = us.UrbanScape(3, 100)
In [5]:
#print out the rent distribution of your first urbanscape
print my_first_urbanscape.rent
In [6]:
#print out the income distribution of your first urbanscape
print my_first_urbanscape.income
When you create an UrbanScape, you can also randomize the rent distribution.
You can do this by setting an optional argument randomize
as true. Create an UrbanScape with the same parameter values as above that randomizes the starting rent distribution.
In [7]:
# Create your randomized UrbanScape here, the print the rent and income distribution
my_urbanscape = us.UrbanScape(3, 100, randomize = True)
print my_urbanscape.rent
print my_urbanscape.income
In [8]:
# Create a bigger UrbanScape with a higher rent ceiling.
# Set size to 20 and rent to 100000, randomize = True
my_big_urbanscape = us.UrbanScape(20, 100000, randomize = True)
#print the rent and distribution
print my_big_urbanscape.rent
print my_big_urbanscape.income
In [ ]:
#build a bigger UrbanScape >> print us.rent
#play with distribution argument >> print us.rent
#%pylab inline and use plot_urbanscape to visualize it
#add agents manually >> plot it
#introduce the create rule >> visualize with animation
#run_experiments function >> plot it
#run_batch experiments function >> plot it